Skip to content

feat(apps): set @datadog/apps backend context#457

Draft
Scott-Meyer wants to merge 4 commits into
masterfrom
scott.meyer/datadog-apps-backend-runtime-entry
Draft

feat(apps): set @datadog/apps backend context#457
Scott-Meyer wants to merge 4 commits into
masterfrom
scott.meyer/datadog-apps-backend-runtime-entry

Conversation

@Scott-Meyer

@Scott-Meyer Scott-Meyer commented Jul 16, 2026

Copy link
Copy Markdown

What and why?

Backend functions using @datadog/apps need the runtime $ context before SDK helpers run. Generated backend entries already receive that context, so the build plugin should initialize the SDK rather than requiring customer-authored handlers to wire it manually.

This follows the existing action-catalog integration pattern while keeping the import optional for projects that do not expose the new SDK backend-internal entry point.

How?

  • Resolve @datadog/apps/backend/internal from the customer project using Node module resolution.
  • Conditionally import setBackendContext into generated backend entries.
  • Call setBackendContext($) after the runtime global is assigned and before action-catalog registration or the customer handler.
  • Share the same generated source between production and dev backend builds.
  • Leave projects using older SDK versions or no SDK unchanged.

The paired SDK change emits @datadog/apps/backend/internal and public backend modules against one shared code-split module, so this setter updates the same context read by SDK helpers.

Related SDK work

QA

A staging URL is not applicable because this only changes build-time generation for backend function bundles.

  • yarn format
  • Targeted ESLint for the four changed files
  • yarn --cwd packages/plugins/apps run typecheck
  • yarn typecheck:all
  • yarn test:unit packages/plugins/apps/src/backend/shared.test.ts packages/plugins/apps/src/backend/virtual-entry.test.ts --runInBand — 31 passing tests
  • yarn cli integrity

Blast radius

Limited to generated Datadog Apps backend entries when the customer project exposes @datadog/apps/backend/internal. Existing action-catalog initialization and projects without that SDK entry point retain their current behavior.

@Scott-Meyer
Scott-Meyer force-pushed the scott.meyer/datadog-apps-backend-runtime-entry branch 2 times, most recently from 86682ae to 145ec69 Compare July 17, 2026 01:18
@Scott-Meyer Scott-Meyer changed the title fix(apps): keep backend runtime context private chore(apps): deprecate legacy backend runtime global Jul 17, 2026
@Scott-Meyer Scott-Meyer changed the title chore(apps): deprecate legacy backend runtime global chore(apps): preserve backend function compatibility Jul 17, 2026
@Scott-Meyer
Scott-Meyer force-pushed the scott.meyer/datadog-apps-backend-runtime-entry branch from 145ec69 to d982beb Compare July 17, 2026 23:44
@Scott-Meyer Scott-Meyer changed the title chore(apps): preserve backend function compatibility feat(apps): inject @datadog/apps backend runtime provider Jul 17, 2026
@Scott-Meyer Scott-Meyer changed the title feat(apps): inject @datadog/apps backend runtime provider feat(apps): set @datadog/apps backend context Jul 18, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Friend, this PR updates the Apps build plugin’s backend virtual-entry code generation to initialize the @datadog/apps backend runtime context ($) inside generated backend function bundles, aligning the generated entries with how the SDK expects helpers to run.

Changes:

  • Add conditional detection of @datadog/apps/backend/internal (via Node module resolution) and generate an optional import for setBackendContext.
  • Emit a generated snippet to call setBackendContext($) after globalThis.$ = $ and before action-catalog registration / handler execution.
  • Extend unit tests to cover presence/absence of the backend-internal import and validate call ordering.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
packages/plugins/apps/src/backend/virtual-entry.ts Adds conditional SDK import and injects backend-context initialization into generated main($) entry.
packages/plugins/apps/src/backend/virtual-entry.test.ts Adds coverage for the new conditional import and ordering constraints.
packages/plugins/apps/src/backend/shared.ts Introduces reusable “is export installed” resolver + new import/snippet constants for Apps backend context.
packages/plugins/apps/src/backend/shared.test.ts Adds unit tests for the new backend-context snippet behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/plugins/apps/src/backend/virtual-entry.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants